<?php defined('_JEXEC') or die('Restricted access'); 
$item = $this->auction;
$template = "templates/tpl_automobil/";
$user = JFactory::getUser();
$db = JFactory::getDBO();
$query = "SELECT id FROM #__auction WHERE product_id = ( SELECT p.id FROM #__pr_product p INNER JOIN #__auction a ON p.id = a.product_id WHERE p.katno < ".$item->katno." AND p.bought = 0 AND a.closed = 0 AND a.published = 1 ORDER BY p.katno DESC LIMIT 0,1)";
$db->setQuery($query);
$back = $db->loadResult();

$query = "SELECT id FROM #__auction WHERE product_id = ( SELECT p.id FROM #__pr_product p INNER JOIN #__auction a ON p.id = a.product_id WHERE p.katno > ".$item->katno." AND p.bought = 0 AND a.closed = 0 AND a.published = 1 ORDER BY p.katno ASC LIMIT 0,1)";
$db->setQuery($query);
$next = $db->loadResult();
if(!$back && !$next){
	$back_link = "javascript:void(0);";
	$next_link = "javascript:void(0);";
} else if(!$back){
	$back_link = "javascript:void(0);";
	$next_link = "index.php?option=com_auction&view=list&auc_id=".($next)."&Itemid=10";
} else if(!$next){
	$back_link = "index.php?option=com_auction&view=list&auc_id=".($back)."&Itemid=10";
	$next_link = "javascript:void(0);";
} else {
	$back_link = "index.php?option=com_auction&view=list&auc_id=".($back)."&Itemid=10";
	$next_link = "index.php?option=com_auction&view=list&auc_id=".($next)."&Itemid=10";
}

$q = "SELECT image, image1, image2, image3, image4 FROM #__pr_product WHERE id = ".$item->product_id;
$db->setQuery($q);
$imageList = $db->loadRow();
$imgNum = 0;
foreach($imageList as $image){
	if($image) $imgNum++;
}
?>
<link rel="stylesheet" type="text/css" href="<?php echo $template;?>fancybox/jquery.fancybox-1.3.4.css" media="screen" />
<script type="text/javascript" src="<?php echo $template;?>fancybox/jquery.mousewheel-3.0.4.pack.js"></script>
<script type="text/javascript" src="<?php echo $template;?>fancybox/jquery.fancybox-1.3.4.pack.js"></script>
<script src="<?php echo $template;?>js/jquery.json-2.2.min.js"></script>
<script language="javascript">
jQuery(document).ready(function(){
	jQuery("#mycarouse").jCarouselLite({
		btnNext: ".next1",
		btnPrev: ".prev1",
		visible : 4,
		scroll: 1,
		speed : 400
	});
	
	jQuery("a[rel=example_group]").fancybox({
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'titlePosition' 	: 'over',
		'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
			return '<span id="fancybox-title-over">Billede ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
		}
	});
});	
</script>
<style>
.init_img{
	display:inline-block;
	height:61px;
	width:98px;
}
#fancybox-title{display:none !important}
</style>
<p>
	<span class="float_left f28"><?php echo $item->katno;?> - <?php echo $item->model;?></span>
    <span class="link-login"><span class="link-login">
    	<input type="text" value="" class="txt_online w123 text_center float_left" onkeyup="setAuctionGo(this.value);" name="auctionNumber" id="auctionNumber" style="height:20px; width:80px;"><a href="#" class="bt_go m5l float_left" id="auctionGo"></a>&nbsp;&nbsp;
    	<a href="index.php?option=com_user&view=user&layout=profile&Itemid=13"><?php if($user->guest==0) {echo  "Min Profil";} ;?></a><a href="index.php?option=com_user&view=login&task=logout&Itemid=13" class="m12l"><?php if($user->guest==0) {echo  "Log ud";};?></a>
    	
    </span></span>
</p>
<div class="cb"></div>
<div class="tt m10b"></div>

<div class="p5t">
	<div class=" p15t">
    	<div class="w462 float_left">
        	<div class="box_katalog">
            	<?php echo "<img src='".JURI::root(false)."thumbnail/timthumb.php?src=".JURI::root(false)."components/com_ecommerce/imgupload/".$item->image."&w=447&h=296&zc=1' title='".$item->model."' alt='".$item->model ."' />";?>
            </div>
            <div class="w451">
            	<?php if($imgNum > 4){?>
              	<div class="nav_prev"><a class="prev1" href="javascript:;"><img src="<?php echo $template;?>images/icon_prev1.png.jpg"></a></div>
                <?php }?>
              	<div id="mycarouse" class="thunb_katalog float_left" style="overflow: hidden;">
                    <ul class="list_img">
                    	<?php if($item->image){?>
                        <li>
                        <a rel="example_group" href="<?php echo JURI::root(false).'components/com_ecommerce/imgupload/'.$item->image;?>" title="" class="init_img">
                        <?php echo "<img src='".JURI::root(false)."thumbnail/timthumb.php?src=".JURI::root(false)."components/com_ecommerce/imgupload/".$item->image."&w=98&h=61&zc=1' title='".$item->model."' alt='".$item->model ."' />";?>
                        </a>
                        </li>
                        <?php }?>
                        <?php if($item->image1){?>
                        <li>
                        <a rel="example_group" href="<?php echo JURI::root(false)."components/com_ecommerce/imgupload/".$item->image1;?>" class="init_img" >
                        <?php echo "<img src='".JURI::root(false)."thumbnail/timthumb.php?src=".JURI::root(false)."components/com_ecommerce/imgupload/".$item->image1."&w=98&h=61&zc=1' title='".$item->model."' alt='".$item->model ."' />";?>
                        </a>
                        </li>
                        <?php }?>
                        <?php if($item->image2){?>
                        <li>
                        <a rel="example_group" href="<?php echo JURI::root(false)."components/com_ecommerce/imgupload/".$item->image2;?>" class="init_img">
                        <?php echo "<img src='".JURI::root(false)."thumbnail/timthumb.php?src=".JURI::root(false)."components/com_ecommerce/imgupload/".$item->image2."&w=98&h=61&zc=1' title='".$item->model."' alt='".$item->model ."' />";?>
                        </a>
                        </li>
                        <?php }?>
                        <?php if($item->image3){?>
                        <li>
                        <a rel="example_group" href="<?php echo JURI::root(false)."components/com_ecommerce/imgupload/".$item->image3;?>" class="init_img">
                        <?php echo "<img src='".JURI::root(false)."thumbnail/timthumb.php?src=".JURI::root(false)."components/com_ecommerce/imgupload/".$item->image3."&w=98&h=61&zc=1' title='".$item->model."' alt='".$item->model ."' />";?>
                        </a>
                        </li>
                        <?php }?>
                        <?php if($item->image4){?>
                        <li>
                        <a rel="example_group" href="<?php echo JURI::root(false)."components/com_ecommerce/imgupload/".$item->image4;?>" class="init_img">
                        <?php echo "<img src='".JURI::root(false)."thumbnail/timthumb.php?src=".JURI::root(false)."components/com_ecommerce/imgupload/".$item->image4."&w=98&h=61&zc=1' title='".$item->model."' alt='".$item->model ."' />";?>
                        </a>
                        </li>
                        <?php }?>
                    </ul>
                	<div class="cb"></div>
              	</div>
                <?php if($imgNum > 4){?>
              	<div class="nav_next"><a class="next1" href="javascript:;"><img src="<?php echo $template;?>images/icon_next1.png.jpg" /></a></div>
                <?php }?>
              	<div class="cb"></div>
            </div>
             <!--<div class="box_katalog m20t m20b">
				<object width="450" height="336" border="0" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000">
                    <param value="clientView.swf" name="movie">
                    <param value="transparent" name="wmode">
                    <embed width="450" height="336" type="application/x-shockwave-flash" wmode="transparent" pluginspage="http://www.macromedia.com/go/get/flashplayer" src="clientView.swf">
                </object>
			</div>-->
            <div class="p15t w451">
            	<?php 
				/*if($item->video){
				?>
                <div class="box_text_katalog_detail">
                    <iframe width="447" height="250" frameborder="0" allowfullscreen="" src="<?php echo $item->video;?>"></iframe>
                </div>
                <?php }*/?>
                <div class="box_text_katalog_detail m20t">
                    <div class="title_text_katalog">Information</div>
                    <div class="p10">
                        <?php echo $item->comment;?>
                    </div>
                </div>
                <div class="cb"></div>
			</div>
            <div class="thunb_online">
            	<!--<a class="bt_cu float_left" href="<?php echo $back_link;?>">Tilbage auktion</a>
                <a class="bt_cu float_left m12l" href="<?php echo $next_link;?>">Næste auktion</a>
              	<p class="cb"></p>-->
              	<a class="bt_auction m10t" href="javascript:void(0);" onclick="endAuction();" id="endBtn">Auktion vundet!</a>
                <span id="loadingPrice" style="display:block; clear:both; text-align:center;"></span>
            </div>
		</div>
        <div class="w276 float_right">
			<div class="box_derip_katalog1 box_text_katalog_detail">
            <div class="title_text_katalog">Tilmelding af bil Min</div>
              <div class="p10">
                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                  	<td colspan="2" align="left"><a onclick="postFacebookWallDetail('<?php echo "http://".$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];?>')" href="javascript:void(0);"><img src="images/sharefb.jpg" alt=""/></a></td>
                  </tr>
                  <tr>
                    <td width="35%"><strong>Tilmelding af bilen Biltype: </strong></td>
                    <td width="65%"><?php echo $item->car_type;?></td>
                  </tr>
                  <tr>
                    <td><strong>Mærke/Model:</strong></td>
                    <td><?php echo $item->model;?></td>
                  </tr>
                  <tr>
                    <td><strong>Brændstof:</strong></td>
                    <td><?php echo $item->fuel;?></td>
                  </tr>
                  <tr>
                    <td><strong>1st Reg.: </strong></td>
                    <td><?php echo $item->register_day;?></td>
                  </tr>
                  <tr>
                    <td><strong>Seneste syn:</strong> </td>
                    <td><?php echo $item->view_day;?></td>
                  </tr>
                  <tr>
                    <td><strong>Skal synes: </strong></td>
                    <td><?php if($item->registry) echo "Ja"; else echo "Nej";?></td>
                  </tr>
                  <tr>
                    <td><strong>Stand/Kategori:</strong></td>
                    <td><?php echo $item->stand;?></td>
                  </tr>
                  <tr>
                    <td><strong>Km.stand: </strong></td>
                    <td><?php echo $item->km;?></td>
                  </tr>
                   <tr>
                    <td><strong>Registeringsnummer: </strong></td>
                    <td><?php echo $item->carid;?></td>
                  </tr>
                  <?php if($item->color){?>
                   <tr>
                    <td><strong>Farve: </strong></td>
                    <td><?php echo $item->color;?></td>
                  </tr>
                  <?php }?>
                   <?php /* if($item->color_type){?>
                   <tr>
                    <td><strong>Lakstand: </strong></td>
                    <td><?php echo $item->color_type;?></td>
                  </tr>
                  <?php }?>
                   <?php if($item->cabin_color){?>
                   <tr>
                    <td><strong>Kabinefarve: </strong></td>
                    <td><?php echo $item->cabin_color;?></td>
                  </tr>
                  <?php }*/?>
                   <?php if($item->chassis){?>
                   <tr>
                    <td><strong>Stelnummer: </strong></td>
                    <td><?php echo $item->chassis;?></td>
                  </tr>
                  <?php }?>
                </table>
              </div>
            </div>
            
            <div class="cb"></div>
            <div class="m20t"></div>
            <?php if($item->show_status){?>
            <h5 style="padding-left:3px;"><b>MINDSTEPRIS <span class="red_color" id="desired"><?php if($item->currentprice >= $item->desiredprice) echo 'OPNÅET';else echo 'IKKE OPNÅET';?></span></b></h5>
            <?php }?>
            
            <div class="bid-price">DKK <span id="currentPriceLabel"></span>,-</div>
            <!--<div class="bid-price-next">DKK <span id="nextPriceLabel"></span>,-</div>-->
            <!--<div id="displayAuction" <?php if($item->closed == 0){?>style="display: block;"<?php } else {?>style="display: none;"<?php }?>>-->
            <div id="displayAuction" style="display: block;">
                <div class="p5t p4l">
                    <a class="btn-bid m5r" href="javascript:void(0);" onclick="sumNextBid(100);">100</a>
                    <a class="btn-bid m5r" href="javascript:void(0);" onclick="sumNextBid(500);">500</a>
                    <div class="cb"></div>
                </div>
                <div class="p5t p4l m10t">
                    <input type="text" value="Fri tekst til at skrive pris" class="txt_online w259 text_center" name="textPrice"  id="textPrice" onclick="this.value = '';" onkeyup="setNextPrice(this.value);">
                </div>
                <a class="bt_send m5l m5t" href="javascript:void(0);" onclick="sendPrice();"></a>
            </div>
            <div class="m15t">
            	<input type="text" value="<?php if($item->winid == "0") echo "Profil nummer"; else echo $item->winid;?>" class="txt_online w123 text_center float_left" onclick="this.value = '';" onkeyup="setProfileNumber(this.value);" name="profileNumber" id="profileNumber">
            	<a href="#" class="bt_save m5l float_left" id="sendProfileNumber"></a>
            </div>
          <p class="cb"></p>
        </div>
    </div>
</div>
<input type="hidden" id="currentPrice" value="<?php echo $item->currentprice;?>" />
<input type="hidden" id="nextPrice" value="" />
<script language="javascript" type="text/javascript">
jQuery(document).ready(function(){
	var bid = 0; i = 1;
	jQuery("#nextPrice").val(parseInt(jQuery("#currentPrice").val()) + 1000);
	jQuery("#currentPriceLabel").html(jQuery("#currentPrice").val());
	//jQuery("#nextPriceLabel").html(jQuery("#nextPrice").val());
	
	setProfileNumber = function(number){
		jQuery('#sendProfileNumber').attr('href','index.php?option=com_auction&task=saveProfileNumber&auc_id=<?php echo $item->id;?> &pn='+number);
	}
	
	setAuctionGo  = function(number){
		jQuery('#auctionGo').attr('href','index.php?option=com_auction&view=list&auc_id='+number+'&Itemid=10');
	}
	
	sumNextBid = function(money){
		if(bid == 0){
			jQuery("#nextPrice").val(parseInt(jQuery("#currentPrice").val()) + money);
		} else {
			jQuery("#nextPrice").val(parseInt(jQuery("#nextPrice").val()) + money);
		}
		//jQuery("#nextPriceLabel").html(jQuery("#nextPrice").val());
		bid = 1;
		sendPrice();
	}
	
	setNextPrice = function(price){
		jQuery("#nextPrice").val(parseInt(price));
		//jQuery("#nextPriceLabel").html(jQuery("#nextPrice").val());
	}
	<?php if($item->closed == 0){?>
	loadPrice = function() {
		jQuery.ajax({
			type: 'POST',
			url: ('<?php echo $this->baseurl ?>/index.php?option=com_auction&task=loadPrice'),
			data: {auc_id: <?php echo $item->id;?>},
			success: function(result){
				result=jQuery.evalJSON(result);
				if(parseInt(result.closed) == 0){
					if( parseInt(result.price) != parseInt( jQuery("#currentPrice").val() ) ){
						jQuery("#currentPrice").val(parseInt(result.price));
						jQuery("#currentPriceLabel").html(jQuery("#currentPrice").val());
						jQuery("#nextPrice").val(parseInt(jQuery("#currentPrice").val()) + 1000);
						//jQuery("#nextPriceLabel").html(jQuery("#nextPrice").val());
					}
					if(!i){
						loadPrice();
					}
				} else {
					jQuery('#displayAuction').css('display','none');
					//clearInterval(intervalID);
				}
			},
			dataType: 'JSON'
		});
    };
	if(i){
		loadPrice();
		i = 0;
	}
	<?php }?>
	sendPrice = function(){
		i = 1;
		jQuery.ajax({
			type: 'POST',
			url: ('<?php echo $this->baseurl ?>/index.php?option=com_auction&task=sendPrice'),
			data: {price: jQuery("#nextPrice").val(), user_id: <?php echo $user->id;?>, auc_id: <?php echo $item->id;?>},
			success: function(result){
				result=jQuery.evalJSON(result);
				if(parseInt(result.closed) == 0){
					bid = 0;
					jQuery("#currentPrice").val(parseInt(result.price));
					jQuery("#currentPriceLabel").html(jQuery("#currentPrice").val());
					jQuery("#nextPrice").val(parseInt(jQuery("#currentPrice").val()) + 1000);
					//jQuery("#nextPriceLabel").html(jQuery("#nextPrice").val());
					jQuery("#textPrice").val('');
					i = 0;
					loadPrice();
				} else {
					alert('This auction is closed');
				}
			},
			dataType: 'JSON'
		});
	}
	
	endAuction = function(){
		jQuery('#endBtn').css('display','none');
		$("#loadingPrice").html('<img src="templates/tpl_automobil/images/loading.gif">');
		jQuery.ajax({
			type: 'POST',
			url: ('<?php echo $this->baseurl ?>/index.php?option=com_auction&task=endAuction'),
			data: {auc_id: <?php echo $item->id;?>},
			success: function(result){
				result=jQuery.evalJSON(result);
				if(parseInt(result.closed) == 1){
					//alert('Denne auktion er lukket. Vind prisen er '+result.price);
					//location.href = 'index.php?option=com_auction&view=list&auc_id=<?php echo $next;?>&Itemid=10';
					$('#closeImg').css('display','none');
					$('#alert').html('Denne auktion er lukket');
					$('#backoverlay').show();
					$('#show_popup').show();
					setTimeout("location.href = 'index.php?option=com_auction&view=list&auc_id=<?php echo $next;?>&Itemid=10';", 3000);
				} else {
					alert('End auction fail');
				}
			},
			dataType: 'JSON'
		});
	}
});
</script>